MadPython for MadEdit Mod
====
Backgroud:
====
MadEdit is a cross-platform Text/Hex Editor written in C++  wxWidgets.
MadEdit supports many useful functions, e.g. SyntaxHighlightings, WordWraps, 
Encodings, Column/Hex Modes, and a Plugin system(not work yet).
In HexMode, MadEdit can open large files which size is up to 32GB (INT_MAX*16).

About:
====
MadPython is a minimized Python which is used as an embedded macro script for 
automation of MadEdit-Mod. The Python is based on the work of Adie
(http://www.adintr.com/article/blog/embedpython_source.html) and was updated 
to Python 2.7.16. Lots of Python modules were removed to reduce the size of it. 
So, you may get errors while importing some of the standard modules. However, 
I don't think it's a problem for the purpose to use it as a macro script language.


Below is the list of the functions supported by MadPython. It's not a good doc 
and it's to be improved. It's only for the advanced users to try and test.

Note: Don't support MadPython recording/Playing in Hex Mode

Note: The APIs are listed as C++ functions.

Note:
    Not supported Python modules:
    cPickle, _io, datetime, _random, cStringIO, _lsprof, _collections, _struct,
    _sre, time, _locale, _headq, _functools, _weakref, itertools, _ctypes and
    all the modules that was implemented by Python, Eg, re, shutil, etc.

    Not supported Python internal ojbects: bytearray, memoryobject

Note:
    You can still extend MadPython by writing a module for it just like the 
    extention module for Python. Eg. https://docs.python.org/2/tutorial/modules.html

C++ Key word|In Python's world
------------|------------------
void        |No return value
int/long    |integer
string      |string
tuple       |tuple
bool        |bool


Simple examples:
====
1. Find all "abc" in current file, not using regular expression, case insensitive, 
not whole word match(Simulate the Find All of Find Dialog)
    me=MadEdit()  # Create a MadEdit object
    res = me.FindTextAll("a", False, False, False)

    print res #how many

2. Replace "\r\n"(Dos/Windows) to "\n"(Unix) by regular expression, then replace 
double line feedings with single one
    me=MadEdit() # Create a MadEdit object
    res = me.ReplaceTextAll("\r\n", "\n", True, False, False)

    res = me.ReplaceTextAll("\n\n", "\n", True, False, False)

3. Move caret to line #10
    me=MadEdit() # Create a MadEdit object
    me.GoToLine(10)

4. Insert 10 "A"s at current caret position(Or use InsertStr for unicode string====python only has string)
    me=MadEdit() # Create a MadEdit object
    for i in range(10):
        me.InsertWChar(65) # Or me.InsertStr('A') or me.InsertStr("A")

5. Use Recording/Playing to see advanced examples!!

Supported method list:
====
void ProcessCommand(int command)
void CharFirst()
void CharLast()
void CaretCommandFirst()
void Left()
void Right()
void Up()
void Down()
void BeginLine()
void EndLine()
void BeginDoc()
void EndDoc()
void PrevPage()
void NextPage()
void PrevWord()
void NextWord()
void LeftBrace()
void RightBrace()
void CaretCommandLast()
void SelCommandFirst()
void SelLeft()
void SelRight()
void SelUp()
void SelDown()
void SelBeginLine()
void SelEndLine()
void SelBeginDoc()
void SelEndDoc()
void SelPrevPage()
void SelNextPage()
void SelPrevWord()
void SelNextWord()
void SelLeftBrace()
void SelRightBrace()
void SelCommandLast()
void Return()
void ReturnNoIndent()
void Tab()
void InsertTabChar()
void Delete()
void BackSpace()
void DelPrevWord()
void DelNextWord()
void ToggleInsertMode()
void InsertWChar(int key)
void InsertStr(std::string str)
void InsertIncrementalNumber(int initial, int step, int total, int stepType,
                        int fmt, int align, bool zeroPad)
void InsertNewline()
void ScrollLineUp()
void ScrollLineDown()
void ScrollPageUp()
void ScrollPageDown()
void ScrollLeft()
void ScrollRight()
void GoToLine(int line)
void Goto(long pos)
void GoToLineColumn(int line, int column)
void SetSyntax(std::string title)
std::string GetSyntaxTitle()
void LoadDefaultSyntaxScheme()
void SetEncoding(std::string encname)
std::string GetEncodingName()
std::string GetEncodingDescription()
long GetEncodingType()
bool GetRecordCaretMovements()
void RecordCaretMovements()
void NotRecordCaretMovements()
void SetTextFont(std::string name, int size, bool forceReset)
void SetHexFont(std::string name, int size, bool forceReset)
mad_py::tuple GetTextFont()
mad_py::tuple GetHexFont()
mad_py::tuple GetFontNameSize()
void SetFontA(std::string name, int size)
void FixedWidthMode()
void NoFixedWidthMode()
bool GetFixedWidthMode()
void SetLineSpacing(int percent)
long GetLineSpacing()
void TextMode()
void ColumnMode()
void HexMode()
long GetEditMode()
void SingleLineMode()
void MultiLineMode()
void SetTabColumns(long value)
long GetTabColumns()
void SetIndentColumns(long value)
long GetIndentColumns()
void InsertSpacesInsteadOfTab()
void InsertTab()
bool GetInsertSpacesInsteadOfTab()
void WantTab()
void NotWantTab()
bool GetWantTab()
void NoWrap()
void WrapByWindow()
void WrapByColumn()
long GetWordWrapMode()
void ShowEndOfLine()
void ShowTabChar()
void ShowSpaceChar()
void DisplayLineNumber()
void MarkActiveLine()
void DisplayLineNumber()
void DisplayBookmark()
void Display80ColHint()
void HideEndOfLine()
void HideTabChar()
void HideSpaceChar()
void HideLineNumber()
void HideMarkActiveLine()
void HideLineNumber()
void HideBookmark()
void Hide80ColHint()
bool GetDisplayLineNumber()
bool GetDisplayLineNumber()
bool GetShowEndOfLine()
bool GetShowTabChar()
bool GetShowSpaceChar()
bool GetMarkActiveLine()
void MarkBracePair()
void NoMarkBracePair()
bool GetMarkBracePair()
long GetMaxColumns()
void SetMaxColumns(long cols)
bool GetAutoIndent()
void AutoIndent()
void NoAutoIndent()
void AutoCompletePair()
void NoAutoCompletePair()
bool GetAutoCompletePair()
void InsertMode()
void OverwriteMode()
bool GetInsertMode()
void SetCaretType(int type)
bool GetMouseSelectToCopy()
void MouseSelectToCopy()
void NoMouseSelectToCopy()
bool GetMouseSelectToCopyWithCtrlKey()
void MouseSelectToCopyWithCtrlKey()
void NoMouseSelectToCopyWithCtrlKey()
void MiddleMouseToPaste(bool value)
void NoMiddleMouseToPaste(bool value)
bool GetMiddleMouseToPaste()
long GetMaxWordWrapWidth()
long GetUCharWidth(int uc)
long GetHexUCharWidth(int uc)
long GetUCharType(int uc)
// all are zero-based
mad_py::tuple GetCaretPositionA()
long GetCaretPositionB()
std::string GetFileName()
long GetFileSize()
bool IsSelected()
bool IsZeroSelected()
long GetLineBeginPos( int line )
long GetSelectionSize()
long GetSelectionBeginPos()
long GetSelectionEndPos()
// return -1 for no selection
mad_py::tuple GetSelectionLineId()
long GetLineCount()
void ConvertNewLineType(MadNewLineType type)
void SetInsertNewLineType(MadNewLineType type)
long GetNewLineType()
long GetInsertNewLineType()
bool IsModified()
long GetModificationTime()
void SetReadOnly(bool value)
bool IsReadOnly()
bool IsTextFile()
std::string GetSelText()
std::string GetRangeText( long begpos, long endpos )
std::string GetText(bool ignoreBOM = true)
void SetText(std::string ws)
// line: zero based
// return true for full line, false for partial line
mad_py::tuple GetLine(int line, size_t maxlen = 0, bool ignoreBOM = true)
long GetLineByPos(int pos)
std::string GetSelHexString(bool withSpace)
std::string GetWordFromCaretPos()
void Delete()
void CutLine()
void DeleteLine()
void InsertTabChar()
void InsertDateTime()
void HighlightWords()
void SelectAll()
void Cut()
void Copy()
void Paste()
void DndBegDrag()
void DndDrop()
bool CanPaste()
void CopyText(std::string txt)
bool CanUndo()
bool CanRedo()
void Undo()
void Redo()
bool CanGoBack()
bool CanGoForward()
void GoBack()
void GoForward()
void SetCaretPosition(int pos, int selbeg=-1, int selend=-1)
bool HasBracePair()
void GoToLeftBrace()
void GoToRightBrace()
// search in [rangeFrom, rangeTo], default in [CaretPos, EndOfDoc]
long FindTextNext(std::string text,
                        bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false,
                        int rangeFrom = -1, int rangeTo = -1)
// search in [rangeFrom, rangeTo], rangeFrom > rangeTo, default in [CaretPos, BeginOfDoc]
long FindTextPrevious(std::string text,
                            bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false,
                            int rangeFrom = -1, int rangeTo = -1)
// search in [rangeFrom, rangeTo], default in [CaretPos, EndOfDoc]
long FindHexNext(std::string hexstr, int rangeFrom = -1, int rangeTo = -1)
// search in [rangeFrom, rangeTo], rangeFrom > rangeTo, default in [CaretPos, BeginOfDoc]
long FindHexPrevious(std::string hexstr, int rangeFrom = -1, int rangeTo = -1)
// replace the selected text that must match expr
long ReplaceText(std::string expr, std::string fmt,
                             bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false,
                             int rangeFrom = -1, int rangeTo = -1)
long ReplaceTextNoDoubleCheck(std::string expr, std::string fmt,
                             bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false,
                             int rangeFrom = -1, int rangeTo = -1)
long ReplaceHex(std::string expr, std::string fmt,
                             int rangeFrom = -1, int rangeTo = -1)
// return the replaced count or SR_EXPR_ERROR
long ReplaceTextAll(std::string expr, std::string fmt,
                    bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false,
                    int rangeFrom = -1, int rangeTo = -1)
long ReplaceHexAll(std::string expr, std::string fmt,
                    int rangeFrom = -1, int rangeTo = -1)
// list the matched data to pbegpos  pendpos
// return the found count or SR_EXPR_ERROR
long FindTextAll(std::string expr, bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bDotMatchNewline = false)
long FindHexAll(std::string expr)
bool LoadFromFile(std::string filename, std::string encoding=std::string(""))
bool SaveToFile(std::string filename)
bool Reload()
// if the file is modified by another app, reload it.
bool ReloadByModificationTime()
// restore pos in Reload(), ConvertEncoding()
void RestorePosition(int pos, int toprow)
// write back to the original FileName
// if FileName is empty, ask the user to get filename
// return wxID_YES(Saved), wxID_NO(Not Saved), or wxID_CANCEL
long Save(bool ask, std::string title, bool saveas)
void ToggleBookmark()
void GotoNextBookmark()
void GotoPreviousBookmark()
void ConvertEncoding(std::string newenc, int flag)
void ConvertChineseA(int flag)
bool HasBOM()
void ToggleBOM()
void IncreaseDecreaseIndent(bool incIndent)
bool HasLineComment()
void CommentUncomment(bool comment)
void ToUpperCase()
void ToLowerCase()
void InvertCase()
void Capitalize()
void ToHalfWidth(bool ascii=true, bool japanese=true, bool korean=true, bool other=true)
void ToFullWidth(bool ascii=true, bool japanese=true, bool korean=true, bool other=true)
void TrimTrailingSpaces()
void DeleteEmptyLines()
void DeleteEmptyLinesWithSpaces()
void JoinLines()
// startline<0 : sort all lines otherwise sort [beginline, endline]
void SortLines(MadSortFlags flags, int beginline, int endline)
// convert WordWraps to NewLine-chars in the SelText or whole file
void ConvertWordWrapToNewLine()
// convert NewLine-chars to WordWraps in the SelText
void ConvertNewLineToWordWrap()
void ConvertSpaceToTab()
void ConvertTabToSpace()
void CopyAsHexString(bool withSpace)
void CopyRevertHex(std::string delimiters)
mad_py::tuple WordCount(bool selection)
void ColumnAlignLeft()
void ColumnAlignRight()
void InsertIncrementalNumber(int initial, int step, int total, int stepType, int fmt, int align, bool zeroPad, std::string prefix, std::string  postfix)
void Astyle()
void XMLFormat()
void Markdown2Html()
void Html2PlainText()
void SetColumnSelection(int startlineid, int startxpos, int hlines, int wlines)
void SelectWholeLine()
long GetIndentCountByPos( long endpos )
int MsgBox(std::string message, std::string caption = "Message", long style = wxOK | wxCENTRE)
std::string InputBox(std::string message, std::string caption = "Input Text")
void SetInsertPairForSelection( bool value )
bool GetInsertPairForSelection()
bool IsZeroSelected()
void ToggleBookmarkInSearch( bool bookmark )
void CutDelBookmarkedLines( bool copyLines = false )
void DeleteUnmarkedLines()
void CopyUnmarkedLines()
void CutUnmarkedLines()
void CopyCutDeleteUnmarkedLines( bool copyLines = false, bool deleteLines = false )
void ReplaceBookmarkedLines()

MadEditCommand
====
None
CharFirst
CharLast
CaretCommandFirst
Left
Right
Up
Down
BeginLine
EndLine
BeginDoc
EndDoc
PrevPage
NextPage
PrevWord
NextWord
LeftBrace
RightBrace
CaretCommandLast
SelCommandFirst
SelLeft
SelRight
SelUp
SelDown
SelBeginLine
SelEndLine
SelBeginDoc
SelEndDoc
SelPrevPage
SelNextPage
SelPrevWord
SelNextWord
SelLeftBrace
SelRightBrace
SelCommandLast
HighlightWords
SeltAll
ScrollLineUp
ScrollLineDown
ScrollPageUp
ScrollPageDown
ScrollLeft
ScrollRight
Return
ReturnNoIndent
Tab
InsertTabChar
Delete
BackSpace
DelPrevWord
DelNextWord
CutLine
DeleteLine
Undo
Redo
Cut
Copy
Paste
ToggleInsertMode
TextMode
ColumnMode
HexMode
NoWrap
WrapByWindow
WrapByColumn
ToggleWindow
IncreaseIndent
DreaseIndent
Comment
Uncomment
ToUpperCase
ToLowerCase
InvertCase
ToHalfWidth
ToFullWidth
InsertDateTime

Note: Some of the command is meanless with scriptin, such like MouseNotify. And some of them
have meanfull clone like ToUpperCase, Paste, etc

MadWordWrapMode
====
NoWrap
WrapByWindow
WrapByColumn

MadEditMode
====
TextMode
ColumnMode
HexMode

MadCaretType
====
VerticalLine
HorizontalLine
Block

MadNewLineType
====
Default
DOS 
UNIX 
MAC

MadConvertEncodingFlag
====
None
SC2TC// Simplified Chinese  ==> Traditional Chinese
TC2SC// Traditional Chinese ==> Simplified Chinese
JK2TC// Japanese Kanji      ==> Traditional Chinese
JK2SC// Japanese Kanji      ==> Simplified Chinese
C2JK  // TradSimp Chinese   ==> Japanese Kanji

MadNumberingStepType
====
Linear
Exponential

MadNumberFormat
====
DEC
HEX
BIN
OCT

MadNumberAlign
====
Left
Right

MadSortLinesFlags
====
Ascending
Descending
CaseSensitive
RemoveDuplicate
NumericSort

MadDlgStyle
====
YES
OK
NO
CANCEL
APPLY
CLOSE
NO_DEFAULT
CANCEL_DEFAULT
ICON_WARNING_EXCLAMATION
ICON_ERROR_HAND_STOP
ICON_QUESTION
ICON_INFORMATION
ICON_NONE
CENTRE

MadMsgBoxRet
====
OK
CANCEL
APPLY
YES
NO

Author:
====
Alston Chen <madedit@gmail.com>
Minggang Li <minggang.li@gmail.com>

Links:
====
MadEdit: http://sourceforge.net/projects/madedit/
MadEdit-Mod: http://sourceforge.net/projects/madedit-mod/
wxWidgets: http://www.wxwidgets.org
wxDevCpp: http://wxdsgn.sourceforge.net
Boost: http://www.boost.org
Open Clip Art Library: http://www.openclipart.org

